﻿using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using SportsStore.Domain.Abstract;
using SportsStore.Domain.Entities;
using SportsStore.WebUI.Controllers;

namespace SportsStore.UnitTests
{
    [TestClass]
    public class NavControllerTest
    {
        [TestMethod]
        public void Can_Create_Categories()
        {
            // Arrange
            var products = new List<Product>()
            {
                new Product() { Category = "C1" },
                new Product() { Category = "C1" },
                new Product() { Category = "C2" },
                new Product() { Category = "C2" },
                new Product() { Category = "C2" },
            };

            var mockRepository = new Mock<IProductRepository>();
            mockRepository.Setup(repo => repo.Products).Returns(products.AsQueryable());

            var controller = new NavController(mockRepository.Object);

            // Act
            var result = controller.Menu().Model as IEnumerable<string>;

            // Assert
            Assert.AreEqual(2, result.Count(), "There has to be two categories");
            Assert.AreEqual("C1", result.First(), "Should contain the expected category");
            Assert.AreEqual("C2", result.Last(), "Should contain the expected category");
        }

        [TestMethod]
        public void ViewBag_ShouldContain_SelectedProperty()
        {
            // Arrange
            var products = new List<Product>()
            {
                new Product() { Category = "C1" },
                new Product() { Category = "C1" },
                new Product() { Category = "C2" },
                new Product() { Category = "C2" },
                new Product() { Category = "C2" },
            };

            var mockRepository = new Mock<IProductRepository>();
            mockRepository.Setup(repo => repo.Products).Returns(products.AsQueryable());

            var controller = new NavController(mockRepository.Object);

            // Act
            var viewBag = controller.Menu("SCategory").ViewBag;
            string selectedCategory = viewBag.SelectedCategory;

            // Assert
            Assert.AreEqual("SCategory", selectedCategory, "The selected category should match");
        }
    }
}
